00001 // Emacs Mode Line: -*- Mode:c++;-*- 00002 /* 00003 * Copyright (c) 2013 Battelle Memorial Institute 00004 * Licensed under modified BSD License. A copy of this license can be found 00005 * in the LICENSE file in the top level directory of this distribution. 00006 */ 00007 // ------------------------------------------------------------- 00008 /** 00009 * @file stat_block.hpp 00010 * @author Bruce Palmer 00011 * @date 2018-09-11 00012 * 00013 * @brief 00014 * This is a utility that is designed to allow users to create a large 00015 * distributed table of data that can subsequently be use for statistical 00016 * analysis. Values in the table are masked so that only values that have been 00017 * deemed relevant according to some criteria are included in the analysis. 00018 * 00019 */ 00020 00021 // ------------------------------------------------------------- 00022 00023 #ifndef _stat_block_hpp_ 00024 #define _stat_block_hpp_ 00025 00026 #include <ga.h> 00027 #include <map> 00028 #include <vector> 00029 #include "gridpack/parallel/communicator.hpp" 00030 00031 namespace gridpack { 00032 namespace analysis { 00033 00034 class StatBlock { 00035 private: 00036 // Simple data struct to keep track of row labels 00037 typedef struct { 00038 int gidx; 00039 int idx1; 00040 int idx2; 00041 char tag[3]; 00042 } index_set; 00043 00044 public: 00045 /** 00046 * Constructor 00047 * @param comm communicator on which StatBlock is defined 00048 * @param nrows number of rows in data array 00049 * @param ncols number of columns in data array 00050 */ 00051 StatBlock(const parallel::Communicator &comm, int nrows, int ncols); 00052 00053 /** 00054 * Default destructor 00055 */ 00056 ~StatBlock(void); 00057 00058 /** 00059 * Add a column of data to the stat block 00060 * @param idx index of column 00061 * @param vals vector of column values 00062 * @param mask vector of mask values 00063 */ 00064 void addColumnValues(int idx, std::vector<double> vals, std::vector<int> mask); 00065 00066 /** 00067 * Add index and device tag that can be used to label rows 00068 * @param indices vector of indices 00069 * @param tags vector of character tags 00070 */ 00071 void addRowLabels(std::vector<int> indices, std::vector<std::string> tags); 00072 00073 /** 00074 * Add two branch indices and device tag that can be used to label rows 00075 * @param idx1 vector of index 1 00076 * @param idx2 vector of index 2 00077 * @param tags vector of character tags 00078 */ 00079 void addRowLabels(std::vector<int> idx1, std::vector<int> idx2, 00080 std::vector<std::string> tags); 00081 00082 /** 00083 * Add the minimum allowed value per row 00084 * @param max vector containing minimum value for each row 00085 */ 00086 void addRowMinValue(std::vector<double> min); 00087 00088 /** 00089 * Add the maximum allowed value per row 00090 * @param max vector containing maximum value for each row 00091 */ 00092 void addRowMaxValue(std::vector<double> max); 00093 00094 /** 00095 * Write out file containing mean value and RMS deviation for values in table 00096 * @param filename name of file containing results 00097 * @param mval only include values with this mask value 00098 * @param flag if false, do not include tag ids in output 00099 */ 00100 void writeMeanAndRMS(std::string filename, int mval=1, bool flag = true); 00101 00102 /** 00103 * Write out file containing Min an Max values in table for each row 00104 * @param filename name of file containing results 00105 * @param mval only include values with this mask value or greater 00106 * @param flag if false, do not include tag ids in output 00107 */ 00108 void writeMinAndMax(std::string filename, int mval=1, bool flag = true); 00109 00110 /** 00111 * Write out file containing number of mask entries at each row that 00112 * correspond to a given value 00113 * @param filename name of file containing results 00114 * @param mval count number of times this mask value occurs 00115 * @param flag if false, do not include tag ids in output 00116 */ 00117 void writeMaskValueCount(std::string filename, int mval, bool flag = true); 00118 00119 /** 00120 * Sum up the values in the columns and print the result as a function 00121 * of column index 00122 * @param filename name of file containing results 00123 * @param mval only include values with this mask value or greater 00124 */ 00125 void sumColumnValues(std::string filename, int mval=1); 00126 private: 00127 00128 int p_data; 00129 int p_mask; 00130 int p_type; 00131 int p_tags; 00132 int p_bounds; 00133 00134 bool p_max_bound; 00135 bool p_min_bound; 00136 bool p_branch_flag; 00137 00138 int p_nrows; 00139 int p_ncols; 00140 00141 int p_nprocs; 00142 int p_me; 00143 int p_GAgrp; 00144 00145 MPI_Comm p_comm; 00146 00147 }; 00148 00149 00150 } // namespace gridpack 00151 } // namespace analysis 00152 00153 #endif